#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "rngs.h"

#define DEBUG 0
#define NOISY_TEST 1

// Function being tested: int updateCoins(...) {...}

int TupdateCoins(int player, struct gameState *state, int bonus)
{
  int x, i, c;
  c = state->coins;
  x = updateCoins(player, state, bonus);
  for (i = 0; i < state->handCount[player]; i++){
    if (state->hand[player][i] == copper){
      assert(state->coins == c + 1);
    }
    else if (state->hand[player][i] == silver){
      assert(state->coins == c + 2);
    }
    else if (state->hand[player][i] == gold){
      assert(state->coins == c + 3);
    }
  }
  assert(x==0);
  return 0;
}


int main()
{
  int x, y, randomPlayer, randomBonus;
  struct gameState newGame;
  printf("Now Testing: int updateCoins(...) {...}\n");
  
  SelectStream(2);
  PutSeed((long)14);
  

  for(x = 0; x < 1000; x++){
    for (y = 0; y < sizeof(struct gameState); y++){
      ((char*)&newGame)[y] = Random() * 100;
    }
    randomPlayer = floor(Random() * MAX_PLAYERS);
    randomBonus = Random() * 3;
    newGame.handCount[randomPlayer] = Random() * MAX_HAND;
    newGame.deckCount[randomPlayer] = Random() * MAX_DECK;
    newGame.discardCount[randomPlayer] = Random() * MAX_PLAYERS;

    TupdateCoins(randomPlayer, &newGame, randomBonus);
  }

  printf("Everything checks out according to this test.\n"); 

  return 0;
}
